<?php
require_once('include/inc_database.php');
require_once('include/inc_useraccount.php');
require_once('include/inc_recommendation.php');
require_once('include/inc_reccomment.php');

// Open DB connection.
$dbobj = new DatabaseObject();
$dbobj->OpenConnection();

$recID = $_GET['recID'];

//$user_ar = $dbobj->GetResultsAsNestedArray("SELECT links.* FROM links WHERE username = $username;", 1);
//$user_r = $user_ar[0];


$auth = new UserAccount();

$rec_ar = $dbobj->GetResultsAsNestedArray("SELECT * FROM mr_recommendation WHERE recID = " . ValToSQL_num($recID) . " ORDER BY recID DESC", 1);
$rec_r = $rec_ar[0];
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?=htmlentities($rec_r['artist'])?> - <?=SiteConst('site_name')?></title>

<link rel="shortcut icon" href="images/favicon.gif" type="image/x-icon">
<meta name="viewport" content="width=700"/>

<style type="text/css">

	@import url('rec.css?<?=$CSS_VERSION?>');


	/* Rec override */
	div.rec_class {
		border: solid 1px #ccc;
		border-width: 1px 0 1px;
		background-color: #f2f2f2;
		padding-top: 4px;
		padding-bottom: 4px;
		background-position: 0 3px;
	}

	div.rec_class:hover {
	}

	/* Comment */
	div.cmt_class { margin: 15px 0; }

	div.cmt_class .cmt_info { color: #999; }

	/* Form */
	tr.rec_form_row > td {
		padding-bottom: 8px;
	}

	tr.rec_form_row .info_only {
		color: #888;
		font-style: italic;
	}

	.inset_box .inset_title {
		background-position: 99% 50%;
		background-repeat: no-repeat;
		margin: -3px;
		padding: 3px 5px;
	}
	.inset_box .inset_title:hover { background-color: #eee; }

</style>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>

<script type="text/javascript">
	//document.write("Hello World!");
	function maketoday() {
		document.mainform.updateDate.value = document.mainform.tempDate.value;
		//document.mainform.updateDate.color = "#000088";
	}
	function makeNow(destination_field) {
		//var text_now = "<?=date('Y-m-d H:i:s', time())?>";
		var text_now = "<?=date('Y-m-d H:i', time())?>";
		destination_field.value = text_now;
	}


	function AddCmt_OpenClose(force) {
		var title = document.getElementById('add_cmt_title');
		var body = document.getElementById('add_cmt_body');
		
		if (force == "close" || AddCmt_OpenClose.is_open) {
			title.style.backgroundImage = "url('/1shot/2007/onebulletin/down01.gif')";
			body.style.display = "none";
			AddCmt_OpenClose.is_open = false;
		}
		else if (force == "open" || !AddCmt_OpenClose.is_open) {
			title.style.backgroundImage = "url('/1shot/2007/onebulletin/up01.gif')";
			body.style.display = "block";
			AddCmt_OpenClose.is_open = true;
		}
	}	
	
	function SendRec_OpenClose(force) {
		var title = document.getElementById('send_rec_title');
		var body = document.getElementById('send_rec_body');
		
		if (force == "close" || SendRec_OpenClose.is_open) {
			title.style.backgroundImage = "url('/1shot/2007/onebulletin/down01.gif')";
			body.style.display = "none";
			SendRec_OpenClose.is_open = false;
		}
		else if (force == "open" || !SendRec_OpenClose.is_open) {
			title.style.backgroundImage = "url('/1shot/2007/onebulletin/up01.gif')";
			body.style.display = "block";
			SendRec_OpenClose.is_open = true;
		}
	}

	$(document).ready(function () { AddCmt_OpenClose("open"); });
	$(document).ready(function () { SendRec_OpenClose("close"); });
</script>

</head>

<body>

<div style="float:right;">
	<?=UserAccount::AccountNavHtml()?>
</div>

<h1 style="margin-bottom:10px;">
	<a href="./"><img src="images/logo02b.jpg" align="middle" border="0"/></a>
	<?=SiteConst('site_name')?>
</h1>


<table style="width:100%;">
<tr>
<td style="padding-right:10px;">

	<h6 style="margin-bottom:5px;">Recommendation:</h6>

	<div class="rec_class" id="rec<?=$rec_r['recID']?>">
		<div>Artist: <b><?=htmlentities($rec_r['artist'])?></b></div>
		<?if ($rec_r['album']) {?>
			<div>Album: <b><?=htmlentities($rec_r['album'])?></b></div>
		<?}?>
		<?if ($rec_r['song']) {?>
			<div>Song: <b><?=htmlentities($rec_r['song'])?></b></div>
		<?}?>
		<div><?=Recommendation::DescriptionHtml($rec_r['description'])?></div>
		<div class="rec_info">
			<span class="rec_heading"><?=date("Y-m-d H:i:s", strtotime($rec_r["addedDateTime"]))?></span>
			by <a href="user.php?user=<?=$rec_r['username']?>"><?=htmlentities($rec_r['username'])?></a>
		</div>
		<div style="margin-top:0.5em;">
			Search artist in:
			<?
			$search_ar = $dbobj->GetResultsAsNestedArray("SELECT * FROM mr_searchExternal srh " .
				"WHERE disabled = 0 and searchOnVariable = 'artist' ORDER BY searchName", 200);
			$i = 0;
			foreach ($search_ar as $search_r) {
				$i++;
				echo " [<a href='" . str_replace(" ", urlencode($rec_r['artist']), $search_r['searchPattern']) . "'>" . $search_r['searchName'] . "</a>]";
			}?>
		</div>
		<?if ($auth->AuthenticatedUser() == $rec_r['username']) {?>
			<div><b>[<a href="rec_edit.php?recID=<?=$rec_r['recID']?>">edit</a>]</b></div>
		<?}?>
	</div>

	<?
	// Comments
	$cmt_ar = $dbobj->GetResultsAsNestedArray("SELECT * FROM mr_recComment cmt " .
		"INNER JOIN mr_useraccount usr ON cmt.username = usr.username " .
		"WHERE recID = " . ValToSQL_num($recID) . " AND disabled = 0 ORDER BY commentNumber", 200);
	?>
	
	<h6 style="margin:20px 0 5px;">Comments:</h6>
	<?$i = 0;
	foreach ($cmt_ar as $cmt_r) {
		$i++;?>
		<div class="cmt_class" id="comment<?=$cmt_r['commentNumber']?>">
			<div class="cmt_info">
				<?if ($cmt_r['userIconPath'] != "") {
					echo "<a href='user.php?user=" . $cmt_r['username'] . "'><img src='image.php?usericon=" . $cmt_r['userIconPath'] . "&amp;size=16' align='ABSMIDDLE' style='border:solid 1px #aaa; padding:1px;'/></a>";
				}?>
				<b><i><a href="user.php?user=<?=$cmt_r['username']?>"><?=$cmt_r['username']?></a> said,</i></b>
				&nbsp;<?=date("Y-m-d H:i:s", strtotime($cmt_r["commentDate"]))?>
				<?if ($auth->AuthenticatedUser() == $cmt_r['username']) {?>
					[<a href="comment_edit.php?recID=<?=$recID?>&amp;commentNumber=<?=$cmt_r['commentNumber']?>">edit</a>]
				<?}
				elseif ($auth->AuthenticatedUser() == $rec_r['username'] || $auth->AuthenticatedUser() == $cmt_r['username']) {?>
					<input type="checkbox" name="delete_commentnumber[]"> delete
				<?}?>
			</div>
			<div><?=RecComment::CommentFormat($cmt_r['content'])?></div>
		</div>
	<?}	
	if ($i == 0) {?>
		<div style="margin:15px; font-style:italic;">No comments yet.</div>
	<?}?>


	<div id="add_cmt" class="inset_box" style="margin-top:30px;">
		
		<h5 id="add_cmt_title" class="inset_title" onclick="AddCmt_OpenClose();">Add Comment:</h5>
		
		<div id="add_cmt_body" style="margin-top:5px;">
		<form name="add_form" method="post" action="comment_add.php" onsubmit="document.add_form.robot_detector.value = 'abc' + 'fed';">
			<input type="hidden" name="add_comment" VALUE="on">
			<input type="hidden" name="robot_detector" VALUE="robot">
			<input type="hidden" name="recID" VALUE="<?=$recID?>">

			<?if ($auth->AuthenticatedUser() != "") {?>
				<table style="width:100%;">
				<tr class="rec_form_row">
					<td style="width:120px;">Me:</td>
					<td>
						<input type="hidden" name="username" value="<?=$auth->AuthenticatedUser()?>">
						<?=$auth->AuthenticatedUser()?>
					</td>
				</tr>
				<tr class="rec_form_row">
					<td>Comment:</td>
					<td>
						<textarea name="content" style="width:99%; height:120px;"></textarea>
					</td>
				</tr>
				<tr class="rec_form_row">
					<td></td>
					<td>
						<input type="submit" name="submit" value="Add comment">
					</td>
				</tr>
				</table>
			<?}
			else {?>
				<i><a href="login.php?redirect_to=<?=$_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']?>">Log in</a> to make a comment</i>
			<?}?>
		</form>
		</div>
	</div>

	<div id="send_rec" class="inset_box" style="margin-top:30px;">

		<h5 id="send_rec_title" class="inset_title" onclick="SendRec_OpenClose();">Send this recommendation:</h5>
		
		<div id="send_rec_body" style="">
		<form name="send_form" method="post" action="send_rec.php?<?=$_SERVER['QUERY_STRING']?>" onsubmit="document.send_form.robot_detector.value = 'abc' + 'fed';">
			<input type="hidden" name="send_email" VALUE="on">
			<input type="hidden" name="robot_detector" VALUE="robot">
			<input type="hidden" name="recID" VALUE="<?=$recID?>">

			<p>Know someone who would like this recommendation?&nbsp; Send it to them.&nbsp; Remember to note a place they might be able to listen to said recommendation.</p>

			<table style="width:100%;">
			<tr class="rec_form_row">
				<td style="width:120px;">Your email:</td>
				<td>
					<input type="text" name="from_email" size="30" value="<?=$auth->user_r['email']?>">
					&nbsp; <input type="checkbox" name="bcc_from_email"> bcc this address
				</td>
			</tr>
			<tr class="rec_form_row">
				<td>Friend's email:</td>
				<td><input type="text" name="to_email" size="30" value=""></td>
			</tr>
			<tr class="rec_form_row">
				<td></td>
				<td style="border: solid 1px #ccc; padding: 5px;">
					<span style="font-family:monospace;">
						Someone thinks you'd like this music:
						<br/>Artist: <?=htmlentities($rec_r['artist'])?>
						<?if ($rec_r['album']) {?>
							<br/>Album: <?=htmlentities($rec_r['album'])?>
						<?}?>
						<?if ($rec_r['song']) {?>
							<br/>Song: <?=htmlentities($rec_r['song'])?>
						<?}?>
						<br/><br/><div style="overflow:hidden"><a href="http://plurib.us/musicrecommend/rec.php?recID=<?=$recID?>">http://plurib.us/musicrecommend/rec.php?recID=<?=$recID?></a></div>
						<br/>Message:
					</span>
					<textarea name="send_content" style="width:99%; height:120px;"></textarea>
				</td>
			</tr>
			<tr class="rec_form_row">
				<td></td>
				<td>
					<input type="submit" name="submit" value="Send">
				</td>
			</tr>
			</table>
		</form>
		</div>
	</div>


</td>
<td id="side_menu">
	<ul>

		<?if ($auth->AuthenticatedUser() != "") {?>
			<li style="list-style-image: url('images/my_home01.png');"><a href="user.php?user=<?=$auth->AuthenticatedUser()?>">My recommendation page</a></li>
		<?}?>

		<li style="list-style-image: url('images/back_home01.png');"><a href="./">Back to <?=SiteConst('site_name')?></a></li>
		
		<?if ($username === $auth->AuthenticatedUser()) {?>
			<li><a href="#add_rec">Add new recommendation</a></li>
		<?}?>	
	</ul>

	<hr />


</td>
</tr>
</table>




<hr />

<div style="text-align:center; margin:20px auto;">
	Return to <a href="./"><?=SiteConst('site_name')?></a>
	<br/><br/><a href="http://code.google.com/p/mediarecommend/"><img src="images/poweredby_mediarecommend.png" style="border-width:0;"/></a>
</div>


<?if ($delete_mode) {?>
	<script type="text/javascript">
	alert("You are in update remove mode.  Please remove inappropriate updates using the checkboxes next to each update (if any).  Removed updates will only appear in remove-mode, and will eventually be read by a moderator.  They will then be deleted forever, or return here perminently.  Thanks for your help.");
	</script>
<?}?>

</body>
</html>
